<template>
    <TaskListComponent ref="taskListCom" bus-key="taskDoManageList" model-type="runtime"
                       :table-operations="tableOperations"
                       :list-url="$baseURL.workflow +  '/workflow/task/tasks/do/listPage'">

    </TaskListComponent>
</template>

<script>

    import TaskListComponent from '../../components/task/TaskListComponent.vue'

    let taskRecallButtonCode = 'taskRecallButtonCode'
    export default {
        components:{
            TaskListComponent
        },
        data(){
            return {
                tableOperations:[
                    {
                        action: this.taskRecall,
                        disabledOnMissingSelect:true,
                        code: taskRecallButtonCode,
                        disabled: (row)=>{ return !row.isCanRecall},
                        label:'撤回'
                    }
                ]
            }
        },
        methods:{
            taskRecall(row){
                this.$confirm('确定要撤回'+ row.name +'吗, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.$refs.taskListCom.getTableRef().setOperationButtonLoading(taskRecallButtonCode,true)
                    this.axios.post(this.$baseURL.workflow + '/workflow/task/tasks/' + row.id + '/recall')
                        .then(res => {
                            this.$message.success('撤回成功')
                            // 重新加载数据
                            this.$refs.taskListCom.getTableRef().refreshData()
                        })
                        .catch(error => {
                            if(error.response){
                                if(error.response.status == 401){
                                    return
                                }
                                if(error.response.status == 404){
                                    this.$message.error('数据不存在，请刷新数据再试')
                                }else {
                                    this.$message.error(error.response.data.msg)
                                }
                            }else {
                                this.$message.error('网络错误或服务不可用')
                            }
                        }).finally(()=>{
                        this.$refs.taskListCom.getTableRef().setOperationButtonLoading(taskRecallButtonCode,false)
                    })
                })
            }
        }
    }
</script>

<style scoped>

</style>